package com.hugang.enums;

import java.util.Arrays;

/**
 * 使用enum关键字定义枚举类
 *
 * @author hg
 * @date 2020/6/18 10:01
 */
public class EnumTest {

    public static void main(String[] args) {
        Season spring = Season.SPRING;
        System.out.println(Season.class.getSuperclass());
        //toString()
        System.out.println(spring.toString());
        spring.show();

        //values()：查看枚举类的所有对象
        Season[] values = Season.values();
        System.out.println(Arrays.toString(values));
        Thread.State[] values1 = Thread.State.values();
        System.out.println(Arrays.toString(values1));

        //valueOf(String objName):返回指定名的枚举类对象，若没找到，则抛异常IllegalArgumentException
        Season spring1 = Season.valueOf("SPRING");
        System.out.println(spring1);

    }
}

/**
 * 季节枚举类，可实现接口
 *
 * @author hg
 * @date 2020/6/18
 */
enum Season implements info{

    /**
     * 默认省略了public static final，且不可写
     */
    SPRING("春天"){
        @Override
        public void show() {
            System.out.println("春");
        }
    },
    SUMMER("夏天") {
        @Override
        public void show() {
            System.out.println("夏");
        }
    },
    AUTOMN("秋天") {
        @Override
        public void show() {
            System.out.println("秋");
        }
    },
    WINTER("冬天") {
        @Override
        public void show() {
            System.out.println("冬");
        }
    };

    private final String name;

    /**
     * 默认省略了private，可写可不写
     * @param name
     */
    Season(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    /**
     * 实现方式1，所以枚举类都使用同一个show()方法
     */
//    @Override
//    public void show() {
//        System.out.println("这是一个季节枚举类的对象，叫做:" + name);
//    }
}

interface info{
    void show();
}